package arithmetic;

/**
 * @program: javaLearn
 * @description: 最大子数组求和
 * @author: renhai
 * @Date ：2022/3/10 23:32
 **/
public class Solution {
    public int maxSubArray(int[] nums) {

        int pre = 0, maxAns = nums[0];
        for (int x : nums) {
            pre = Math.max(pre + x, x);
            maxAns = Math.max(maxAns, pre);
        }
        return maxAns;
    }
}
